package cn.xlbweb.cli.controller;

import cn.xlbweb.cli.model.Permission;
import cn.xlbweb.cli.common.ServerResponse;
import cn.xlbweb.cli.common.TableResponse;
import cn.xlbweb.cli.pojo.dto.PermissionsListDTO;
import cn.xlbweb.cli.service.IPermissionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: bobi
 * @date: 2019-02-04 00:55
 * @description:
 */
@RestController
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionService iPermissionService;

    @GetMapping("listPermissions")
    @RequiresPermissions("permission:listPermissions")
    public TableResponse listPermissions(PermissionsListDTO permissionsListDTO,
                                         @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "100") int pageSize) {
        return iPermissionService.listPermissions(permissionsListDTO, pageNum, pageSize);
    }

    @PostMapping("insertPermission")
    @RequiresPermissions("permission:insertPermission")
    public ServerResponse insertPermission(Permission permission) {
        return iPermissionService.insertPermission(permission);
    }

    @PutMapping("updatePermission")
    @RequiresPermissions("permission:updatePermission")
    public ServerResponse updatePermission(Permission permission) {
        return iPermissionService.updatePermission(permission);
    }

    @DeleteMapping("deletePermission")
    @RequiresPermissions("permission:deletePermission")
    public ServerResponse deletePermission(String ids) {
        return iPermissionService.deletePermission(ids);
    }
}
